package com.sgb.kjwl.view.ui.activity.vehicleManagement;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityAddVehicleBinding;
import com.sgb.kjwl.di.vehicleManagement.AddVehicleModule;
import com.sgb.kjwl.di.vehicleManagement.DaggerAddVehicleComponent;
import com.swgk.core.view.entity.DriverAuthDetailEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.GlideEngine;
import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.sgb.kjwl.view.ui.adapter.transport.CardPushAdapter;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.viewmodel.vehicleManagement.AddVehicleAtvModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import javax.inject.Inject;

/**
 * 司机认证
 */

public class AddVehicleActivity extends AppActivity {
    private Thread thread;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_FAILED = 0x0003;

    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2=new ArrayList<>();
    // 三级联动数据
    private List<List<List<AddressEntity>>> opt3=new ArrayList<>();
    private List<AddressEntity<List<AddressEntity>>> cityList;
    //区域列表
    private List<List<AddressEntity>> areaList;

    private GoodsInfoTypeEntity3 goodsInfoTypeEntity3 = new GoodsInfoTypeEntity3();
    private int carLengthTypePosition;
    private int carTypePosition;
    public int DRIVER_LICENS = 1;   //驾驶照
    public int DRIVING_LICENS = 2;  //行驶照
    public int CAR_PHOTO = 3;       //车辆照

    @Inject
    AddVehicleAtvModel viewModel;
    ActivityAddVehicleBinding binding;
    private List<GoodsInfoTypeEntity3> carsLengthData;
    private List<GoodsInfoTypeEntity3> carsTypeData;
    private StringBuilder currentPosition;

    private String province = "";
    private String district = "";
    private String cityCode = "";
    private String carLenNO = "";
    private String carTypeNO = "";
    private int type;
    private Intent intent;
    private List<String> listLicens_driver = new ArrayList<>();
    private List<String> listLicens_driving = new ArrayList<>();
    private List<String> listLicens_carPhoto = new ArrayList<>();
    private int state;
    private String driverLicense;
    private String vehicleLicense;
    private String carImage;
    private String areaName;
    private String mAreaCode;
    private int cityPosition3;
    private int cityPosition1;
    private int cityPosition2;
    private String provinceName;
    private String provinceNo;
    private String cityName;
    private boolean isLoaded = false;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerAddVehicleComponent.builder().appComponent(appComponent).addVehicleModule(new AddVehicleModule(this)).build().inject(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, AddVehicleActivity.class);
        context.startActivity(intent);
    }

    public static void start(Context context, int state) {
        Intent intent = new Intent();
        intent.putExtra("state", state); // 1 是已经提交过的
        intent.setClass(context, AddVehicleActivity.class);
        context.startActivity(intent);
    }

    // 车型车长展示 问题  修改审核 图片添加 按钮么展示
    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_add_vehicle);
        binding.setViewModel(viewModel);

        int state = getIntent().getIntExtra("state", 0);
        if (state == 0) {
            binding.include.titleView.setText("司机认证");
            binding.llState1.setVisibility(View.GONE);
            binding.linearLayout.setVisibility(View.VISIBLE);
//            binding.deleteTv.setVisibility(View.GONE);

        } else {
            binding.include.titleView.setText("司机认证审核状态");
            binding.include.rightView.setText("修改审核信息");
            binding.linearLayout.setVisibility(View.GONE);
            binding.tvName.setEnabled(false);
            binding.tvId.setEnabled(false);
            binding.tvCarNum.setEnabled(false);
            binding.tvPosition.setEnabled(false);
            binding.tvCarLengh.setEnabled(false);
            binding.tvCarModel.setEnabled(false);
            binding.tvCarWeight.setEnabled(false);
            binding.deleteTv.setEnabled(false);
            binding.include.rightView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    binding.linearLayout.setVisibility(View.VISIBLE);
                    binding.tvName.setEnabled(true);
                    binding.tvId.setEnabled(true);
                    binding.tvCarNum.setEnabled(true);
                    binding.tvPosition.setEnabled(true);
                    binding.tvCarLengh.setEnabled(true);
                    binding.tvCarModel.setEnabled(true);
                    binding.tvCarWeight.setEnabled(true);
                    binding.deleteTv.setEnabled(true);
                    binding.llCertificates.setVisibility(View.VISIBLE);
                    binding.llCertificatesDriving.setVisibility(View.VISIBLE);
                    binding.llCertificatesCarphoto.setVisibility(View.VISIBLE);

                }
            });
            binding.llState1.setVisibility(View.VISIBLE);
        }

        binding.include.ivBack.setOnClickListener(view -> {
            finish();
        });

        binding.nextView.setOnClickListener(view -> sumbit());
        binding.tvCarWeight.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
        binding.llPosition.setOnClickListener(view -> {
            hideKeyboard();
            if (null != addressEntityList && addressEntityList.size() > 0) {
                showCityPop();
            } else {
                viewModel.getAddressModel();

            }
        });

        binding.tvCarLengh.setOnClickListener(view -> {
            hideKeyboard();
            showCarLengthTypePop();
        });

        binding.tvCarModel.setOnClickListener(view -> {
            hideKeyboard();
            showCarTypePop();
        });
        binding.rvCardPush.setAdapter(new CardPushAdapter(this));

        binding.ivCertificates.setOnClickListener(view -> {
            getCerImage(DRIVER_LICENS);
            type = DRIVER_LICENS;
        });

        binding.ivCertificatesDriving.setOnClickListener(view -> {
            getCerImage(DRIVING_LICENS);
            type = DRIVING_LICENS;
        });

        binding.ivCertificatesCarphoto.setOnClickListener(view -> {
            getCerImage(CAR_PHOTO);
            type = CAR_PHOTO;
        });
        // 删除图片的方法
        binding.deleteTv.setOnClickListener(view -> {
            binding.rlAdd.setVisibility(View.GONE);
            Objects.requireNonNull(viewModel.filterJson.get()).setDriverLicense("");
        });

        binding.deleteTv2.setOnClickListener(view -> {
            binding.rlAdd2.setVisibility(View.GONE);
            Objects.requireNonNull(viewModel.filterJson.get()).setVehicleLicense("");
        });

        binding.deleteTv3.setOnClickListener(view -> {
            binding.rlAdd3.setVisibility(View.GONE);
            Objects.requireNonNull(viewModel.filterJson.get()).setCarImage("");
        });
        binding.tvName.setSelection(binding.tvName.getText().length());
        binding.tvId.setSelection(binding.tvId.getText().length());
        binding.tvCarNum.setSelection(binding.tvCarNum.getText().length());
        binding.tvCarWeight.setSelection(binding.tvCarWeight.getText().length());

    }

    private void showCityPop() {
        CityPickView cityOption = new CityPickBuilder(this, new OnOptionsSelectListener() {

            private String cityNo;

            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (opt3.get(options1).get(options2).get(options3) == null) {
                    areaName = "";
                } else {
                    areaName = opt3.get(options1).get(options2).get(options3).getName();
                    mAreaCode = opt3.get(options1).get(options2).get(options3).getNo();
                    cityPosition3 = options3;
                    viewModel.userAddressEntity.get().setDistrictName(areaName);
                    viewModel.userAddressEntity.get().setDistrictNo(opt3.get(options1).get(options2).get(options3).getNo());
                }
                String content = addressEntityList.get(options1).getName() + opt2.get(options1).get(options2).getName() + areaName;
                cityPosition1 = options1;
                cityPosition2 = options2;


                if (!TextUtils.isEmpty(areaName)) {
                    viewModel.userAddressEntity.get().setDistrictName(areaName);
                    viewModel.userAddressEntity.get().setDistrictNo(opt3.get(options1).get(options2).get(options3).getNo());
                }
                provinceName = addressEntityList.get(options1).getName();
                viewModel.userAddressEntity.get().setProvinceName(addressEntityList.get(options1).getName());
                provinceNo = addressEntityList.get(options1).getId();
                viewModel.userAddressEntity.get().setProvinceNo(provinceNo);
                cityName = opt2.get(options1).get(options2).getName();
                viewModel.userAddressEntity.get().setCityName(opt2.get(options1).get(options2).getName());
                cityNo = opt2.get(options1).get(options2).getNo();
                viewModel.userAddressEntity.get().setCityNo(cityNo);

                binding.tvPosition.setText(content);

            }
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择车辆位置")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();

    }


    //获取InputMethodManager，隐藏软键盘
    private void hideKeyboard() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        // 隐藏软键盘
        imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getWindowToken(), 0);
    }

    //预览
    private void openPhotoView(List<String> urls) {
        if (intent == null) {
            intent = new Intent();
        }
        intent.setClass(AddVehicleActivity.this, PhotoViewActivity.class);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) urls);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, 0);
        startActivity(intent);
    }

    private void getCerImage(int type) {
        this.type = type;
        MLog.d("type == ", "" + type);
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .loadImageEngine(GlideEngine.createGlideEngine())
                .theme(R.style.picture_default_style)
                .compress(true)//是否压缩
                .minimumCompressSize(10240)//小于10M不压缩
                .maxSelectNum(1)//判断还能选多少张图片
                .forResult(PictureConfig.CHOOSE_REQUEST);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PictureConfig.CHOOSE_REQUEST:
                    MLog.d("type ", type + "");
                    if (DRIVER_LICENS == type) {
                        listLicens_driver = new ArrayList<>();
                        List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                        File file = new File(selectList.get(0).getRealPath());
                        MLog.d("图片路径：", selectList.get(0).getRealPath());
                        if (file.exists()) {
                            MLog.d("图片", "存在");
                        }
                        listLicens_driver.add(selectList.get(0).getRealPath());
                        binding.rlAdd.setVisibility(View.VISIBLE);
                        Glide.with(getActivity()).load(selectList.get(0).getRealPath()).into(binding.addImg);
                        viewModel.uploadMutiFileModel(file, DRIVER_LICENS);

                    } else if (type == DRIVING_LICENS) {
                        listLicens_driving = new ArrayList<>();
                        List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                        File file = new File(selectList.get(0).getRealPath());
                        MLog.d("图片路径：", selectList.get(0).getRealPath());
                        if (file.exists()) {
                            MLog.d("图片", "存在");
                        }
                        listLicens_driving.add(selectList.get(0).getRealPath());
                        binding.rlAdd2.setVisibility(View.VISIBLE);
                        Glide.with(getActivity()).load(selectList.get(0).getRealPath()).into(binding.addImg2);
                        viewModel.uploadMutiFileModel(file, DRIVING_LICENS);

                    } else if (type == CAR_PHOTO) {
                        listLicens_carPhoto = new ArrayList<>();
                        List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                        File file = new File(selectList.get(0).getRealPath());
                        MLog.d("图片路径：", selectList.get(0).getRealPath());
                        if (file.exists()) {
                            MLog.d("图片", "存在");
                        }
                        listLicens_carPhoto.add(selectList.get(0).getRealPath());
                        binding.rlAdd3.setVisibility(View.VISIBLE);
                        Glide.with(getActivity()).load(selectList.get(0).getRealPath()).into(binding.addImg3);
                        viewModel.uploadMutiFileModel(file, CAR_PHOTO);
                    }

            }
        }
    }


    @Override
    protected void init() {
        viewModel.getGoodsTypeData();
        binding.tvCarWeight.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (Float.parseFloat(binding.tvCarWeight.getText().toString().replace("吨", "")) > 999) {
                    MToast.showToast(getActivity(), "额定载重不能大于" + 999 + "吨");
                }
            }
        });

        viewModel.getDriverAuthDetail();
    }

    private void getFilterJson() {
        Objects.requireNonNull(viewModel.filterJson.get()).setCarTypeNo(carTypeNO);
        Objects.requireNonNull(viewModel.filterJson.get()).setCityName(binding.tvPosition.getText().toString());
        Objects.requireNonNull(viewModel.filterJson.get()).setProvinceNo("610000");
        Objects.requireNonNull(viewModel.filterJson.get()).setWeight(binding.tvCarWeight.getText().toString().trim());
        Objects.requireNonNull(viewModel.filterJson.get()).setCityNo(cityCode);
        Objects.requireNonNull(viewModel.filterJson.get()).setDistrictNo("610113");
        Objects.requireNonNull(viewModel.filterJson.get()).setIdCard(binding.tvId.getText().toString().trim());
//        Objects.requireNonNull(viewModel.filterJson.get()).setDriverLicense("https://shigongbang.oss-cn-hangzhou.aliyuncs.com/app/2020/07/1593757196372.jpg");
//        Objects.requireNonNull(viewModel.filterJson.get()).setCarImage("https://shigongbang.oss-cn-hangzhou.aliyuncs.com/app/2020/0 7/1593757257999.jpg");
//        Objects.requireNonNull(viewModel.filterJson.get()).setVehicleLicense("https://shigongbang.oss-cn-hangzhou.aliyuncs.com/app/2020/07/1593757245808.jpg");
        Objects.requireNonNull(viewModel.filterJson.get()).setProvinceName(province);
        Objects.requireNonNull(viewModel.filterJson.get()).setDetailAddress(province + binding.tvPosition.getText().toString() + district);
        Objects.requireNonNull(viewModel.filterJson.get()).setDistrictName(district);
        Objects.requireNonNull(viewModel.filterJson.get()).setCarLenNo(carLenNO);
        Objects.requireNonNull(viewModel.filterJson.get()).setName(binding.tvName.getText().toString().trim());
        Objects.requireNonNull(viewModel.filterJson.get()).setCarNumber(binding.tvCarNum.getText().toString().trim());
    }

    public void getCarsTypeData(List<GoodsInfoTypeEntity3> list) {
        if (null != list && list.size() > 0) {
            carsTypeData = list;
            int size = list.size();
            String[] carsType = new String[size];
            for (int i = 0; i < size; i++) {
                carsType[i] = list.get(i).getName();
            }
        } else {
            MToast.showToast(getActivity(), "数据未加载");
        }
    }

    //获取车长
    public void getCarsLengthData(List<GoodsInfoTypeEntity3> list) {
        if (null != list && list.size() > 0) {
            carsLengthData = list;
            int size = list.size();
            String[] carsLength = new String[size];
            for (int i = 0; i < size; i++) {
                carsLength[i] = list.get(i).getName();
            }
        } else {
            MToast.showToast(getActivity(), "数据未加载");
        }
    }

    //车长选择器
    private void showCarLengthTypePop() {
        OptionsPickerView carLengthTypeOption = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                carLenNO = carsLengthData.get(options1).getNo();
                String content = carsLengthData.get(options1).getName();
                goodsInfoTypeEntity3.setName(carsLengthData.get(options1).getName());
                binding.tvCarLengh.setText(content);
                carLengthTypePosition = options1;
            }
        }).setDecorView(getWindow().getDecorView().findViewById(android.R.id.content)).build();
        if (carsLengthData != null && carsLengthData.size() > 0) {
            carLengthTypeOption.setPicker(carsLengthData);
            carLengthTypeOption.setSelectOptions(carLengthTypePosition);
            carLengthTypeOption.show();
        } else {
            MToast.showToast(getActivity(), "后台无数据！");
        }
    }

    //车类型选择器
    private void showCarTypePop() {
        OptionsPickerView carTypeOption = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                carTypeNO = carsTypeData.get(options1).getNo();
                String content = carsTypeData.get(options1).getName();
                goodsInfoTypeEntity3.setName(carsTypeData.get(options1).getName());
                binding.tvCarModel.setText(content);
                carTypePosition = options1;
            }
        }).setDecorView(getWindow().getDecorView().findViewById(android.R.id.content)).build();
        if (carsTypeData != null && carsTypeData.size() > 0) {
            carTypeOption.setPicker(carsTypeData);
            carTypeOption.setSelectOptions(carTypePosition);
            carTypeOption.show();
        } else {
            MToast.showToast(getActivity(), "后台无数据！");
        }
    }

    private void sumbit() {
        if (TextUtils.isEmpty(binding.tvName.getText().toString().trim())) {
            MToast.showToast(this, "请输入姓名");
            return;
        }
        if (TextUtils.isEmpty(binding.tvId.getText().toString().trim())) {
            MToast.showToast(this, "请输入身份证号");
            return;
        }
        if (TextUtils.isEmpty(binding.tvCarNum.getText().toString().trim())) {
            MToast.showToast(this, "请输入车牌号");
            return;
        }
        if (TextUtils.isEmpty(binding.tvCarLengh.getText().toString().trim())) {
            MToast.showToast(this, "请选择车长");
            return;
        }
        if (TextUtils.isEmpty(binding.tvCarModel.getText().toString().trim())) {
            MToast.showToast(this, "请选择车型");
            return;
        }
        if (TextUtils.isEmpty(binding.tvCarWeight.getText().toString().trim())) {
            MToast.showToast(this, "请输入额定载重");
            return;
        }

        getFilterJson();
        viewModel.getDriverAuthData();
    }

    public void uploadImgSuccess(String urls, int type) {
        if (type == DRIVER_LICENS) {
            Objects.requireNonNull(viewModel.filterJson.get()).setDriverLicense(urls);
        } else if (type == DRIVING_LICENS) {
            Objects.requireNonNull(viewModel.filterJson.get()).setVehicleLicense(urls);
        } else if (type == CAR_PHOTO) {
            Objects.requireNonNull(viewModel.filterJson.get()).setCarImage(urls);
        }
    }

    public void showDetails(DriverAuthDetailEntity data) {
        if (data.getState() == 0) {
            binding.tvStatus.setText("已下架");
            binding.llState1.setVisibility(View.VISIBLE);
            binding.tvStatus.setTextColor(getResources().getColor(R.color.goldenrodColor));
            binding.llStatusDetails.setVisibility(View.VISIBLE);
            binding.tvStatusDetails.setText("您的信息存在违规，请重新提交审核，通过后方可正常使用！");
        } else {
            if (data.getStatus() == 0) {
                binding.tvStatus.setText("审核中");
                binding.tvStatus.setTextColor(getResources().getColor(R.color.color_4A8BF0));
                binding.llStatusDetails.setVisibility(View.GONE);
                binding.include.rightView.setVisibility(View.GONE);
            } else if (data.getStatus() == 1) {
                binding.tvStatus.setText("审核通过");
                binding.tvStatus.setTextColor(getResources().getColor(R.color.color_green_00d3a9));
                binding.llStatusDetails.setVisibility(View.GONE);
                binding.include.rightView.setVisibility(View.VISIBLE);
            } else if (data.getStatus() == 2) {
                binding.tvStatus.setText("审核不通过");
                binding.tvStatus.setTextColor(getResources().getColor(R.color.red));
                binding.llStatusDetails.setVisibility(View.VISIBLE);
                binding.include.rightView.setVisibility(View.VISIBLE);
                binding.llState1.setVisibility(View.VISIBLE);
                binding.tvStatusDetails.setText("您的信息提交不完整，请重新提交审核，通过后方可正常使用！");
            }
        }

        binding.linearLayout.setVisibility(View.GONE);
        binding.llCertificates.setVisibility(View.GONE);
        binding.llCertificatesDriving.setVisibility(View.GONE);
        binding.llCertificatesCarphoto.setVisibility(View.GONE);
        binding.tvName.setEnabled(false);
        binding.tvId.setEnabled(false);
        binding.tvCarNum.setEnabled(false);
        binding.tvPosition.setEnabled(false);
        binding.tvCarLengh.setEnabled(false);
        binding.tvCarModel.setEnabled(false);
        binding.tvCarWeight.setEnabled(false);

        binding.tvName.setText(data.getName());
        binding.tvId.setText(data.getIdCard());
        binding.tvCarNum.setText(data.getCarNumber());
        binding.tvPosition.setText(data.getCityName());
        binding.tvCarLengh.setText(data.getCarLenName());
        binding.tvCarModel.setText(data.getCarTypeName());
        if (data.getWeight() == 0) {
            binding.tvCarWeight.setHint("请输入额定重量");
        } else {
            binding.tvCarWeight.setText(data.getWeight() + "吨");
        }

        if (data.getDriverLicense() != null) {
            binding.rlAdd.setVisibility(View.VISIBLE);
            Glide.with(getActivity()).load(data.getDriverLicense()).into(binding.addImg);
        } else {
            binding.rlAdd.setVisibility(View.GONE);
        }

        if (data.getVehicleLicense() != null) {
            binding.rlAdd2.setVisibility(View.VISIBLE);
            Glide.with(getActivity()).load(data.getVehicleLicense()).into(binding.addImg2);
        } else {
            binding.rlAdd2.setVisibility(View.GONE);
        }

        if (data.getCarImage() != null) {
            binding.rlAdd3.setVisibility(View.VISIBLE);
            Glide.with(getActivity()).load(data.getCarImage()).into(binding.addImg3);
        } else {
            binding.rlAdd3.setVisibility(View.GONE);
        }

        driverLicense = data.getDriverLicense();
        vehicleLicense = data.getVehicleLicense();
        carImage = data.getCarImage();

        MLog.e("展示 图片路径", driverLicense);
        if (!TextUtils.isEmpty(driverLicense)) {
            ArrayList<String> driverLicenseL = new ArrayList<>();
            driverLicenseL.add(driverLicense);
            binding.addImg.setOnClickListener(view -> openPhotoView(driverLicenseL));
        } else {
            binding.addImg.setOnClickListener(view -> openPhotoView(listLicens_driver));
        }

        if (!TextUtils.isEmpty(vehicleLicense)) {
            ArrayList<String> vehicleLicenseL = new ArrayList<>();
            vehicleLicenseL.add(vehicleLicense);
            binding.addImg2.setOnClickListener(view -> openPhotoView(vehicleLicenseL));
        } else {
            binding.addImg2.setOnClickListener(view -> openPhotoView(listLicens_driving));
        }

        if (!TextUtils.isEmpty(carImage)) {
            ArrayList<String> carImageL = new ArrayList<>();
            carImageL.add(carImage);
            binding.addImg3.setOnClickListener(view -> openPhotoView(carImageL));
        } else {
            binding.addImg3.setOnClickListener(view -> openPhotoView(listLicens_carPhoto));
        }
    }

    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> datas) {
        this.addressEntityList = datas;
        if (isLoaded) {
            showCityPop();
        } else {
            mHandler.sendEmptyMessage(MSG_LOAD_DATA);
        }
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {
                        thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                // 子线程中解析省市区数据
                                initJsonData();
                            }
                        });
                        thread.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS:
                    showCityPop();
                    isLoaded = true;
                    break;

                case MSG_LOAD_FAILED:
                    break;
            }
        }
    };

    private void initJsonData() {
        for (AddressEntity<List<AddressEntity<List<AddressEntity>>>> entity : addressEntityList) {
            cityList = new ArrayList<>();
            areaList = new ArrayList<>();
            opt2.add(entity.getChildren());
            for (int i = 0; i < entity.getChildren().size(); i++) {
                cityList.add(entity.getChildren().get(i));
                List<AddressEntity> cityAreaList = new ArrayList<>();
                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (entity.getChildren().get(i).getChildren() == null
                        || entity.getChildren().get(i).getChildren().size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(entity.getChildren().get(i).getChildren());
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
        mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);
    }
}
